{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Extracted from http://zulko.github.io/blog/2014/11/29/data-animations-with-python-and-moviepy/\n",
    "import numpy as np\n",
    "import mayavi.mlab as mlab\n",
    "import  moviepy.editor as mpy\n",
    "\n",
    "duration= 2 # duration of the animation in seconds (it will loop)\n",
    "\n",
    "# MAKE A FIGURE WITH MAYAVI\n",
    "\n",
    "fig_myv = mlab.figure(size=(220,220), bgcolor=(1,1,1))\n",
    "X, Y = np.linspace(-2,2,200), np.linspace(-2,2,200)\n",
    "XX, YY = np.meshgrid(X,Y)\n",
    "ZZ = lambda d: np.sinc(XX**2+YY**2)+np.sin(XX+d)\n",
    "\n",
    "# ANIMATE THE FIGURE WITH MOVIEPY, WRITE AN ANIMATED GIF\n",
    "\n",
    "def make_frame(t):\n",
    "    mlab.clf() # clear the figure (to reset the colors)\n",
    "    mlab.mesh(YY,XX,ZZ(2*np.pi*t/duration), figure=fig_myv)\n",
    "    return mlab.screenshot(antialiased=True)\n",
    "\n",
    "animation = mpy.VideoClip(make_frame, duration=duration)\n",
    "animation.write_gif(\"sinc.gif\", fps=20)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
